package com.sale.salesystem.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.sale.salesystem.entity.DashboardChart;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Delete;
import java.util.List;

@Mapper
public interface DashboardChartMapper extends BaseMapper<DashboardChart> {
    
    @Select("SELECT * FROM dashboard_chart WHERE dashboard_id = #{dashboardId} ORDER BY display_order")
    List<DashboardChart> selectByDashboardId(Long dashboardId);
    
    @Delete("DELETE FROM dashboard_chart WHERE dashboard_id = #{dashboardId}")
    int deleteByDashboardId(Long dashboardId);
    
    @Select("SELECT COUNT(*) FROM dashboard_chart WHERE dashboard_id = #{dashboardId}")
    int countByDashboardId(Long dashboardId);
    
    @Select("SELECT MAX(display_order) FROM dashboard_chart WHERE dashboard_id = #{dashboardId}")
    Integer getMaxDisplayOrder(Long dashboardId);

    /**
     * 批量插入图表
     * @param charts 图表列表
     * @return 插入的记录数
     */
    int batchInsert(List<DashboardChart> charts);
} 